from alg import Solution, print_solution
import time

def test_single_case(n: int):
    """测试单个用例"""
    print(f"\n测试 n = {n}")
    start_time = time.time()
    solution = Solution()
    result = solution.solveNQueens(n)
    end_time = time.time()
    
    print(f"找到 {len(result)} 个解决方案")
    print(f"耗时: {end_time - start_time:.4f} 秒")
    print_solution(result)

def test_from_file():
    """从文件读取测试用例并测试"""
    try:
        with open('test_cases.txt', 'r') as f:
            test_cases = [int(line.strip()) for line in f]
        
        for n in test_cases:
            test_single_case(n)
    except FileNotFoundError:
        print("未找到测试用例文件，请先运行 gen.py 生成测试用例")

if __name__ == "__main__":
    # 测试示例用例
    print("测试示例用例：")
    test_single_case(4)
    test_single_case(1)
    
    # 测试生成的用例
    print("\n测试生成的用例：")
    test_from_file() 